package com.huatai.auth.controller;


import com.huatai.common.util.Kv;
import com.huatai.common.util.StringUtil;

import com.wf.captcha.SpecCaptcha;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * @program: ht-system
 * @description:
 * @author: songxiude
 * @create: 2023-04-27 10:33
 **/
@RestController
@Api(value = "统一认证鉴权", tags = "统一认证鉴权")
public class AuthController {
	@Autowired
	private StringRedisTemplate redisTemplate;

	@GetMapping("/oauth/captcha")
	@ApiOperation(value = "获取图形验证码", notes = "获取图形验证码")
	public Kv captcha() {
		SpecCaptcha specCaptcha = new SpecCaptcha(130, 48, 5);
		String verCode = specCaptcha.text().toLowerCase();
		String key = StringUtil.randomUUID();
		// 存入redis并设置过期时间为30分钟
		redisTemplate.opsForValue().set("ht:captcha:"+key,verCode,30, TimeUnit.SECONDS);
		// 将key和base64返回给前端
		return Kv.create().set("key", key).set("image", specCaptcha.toBase64());
	}

//	@GetMapping("/oauth/getSignCode")
//	@ApiOperation(value = "获取软件授权签名", notes = "获取软件授权签名")
//	public R getSignCode(){
//		String systemSign = LicenseManager.getSystemSign();
//		return R.data(systemSign);
//	}
}
